<template>
  <div>
    <div style="float: right">
      <div style="display: inline-block; color: red;font-weight: bolder;">请选择推送平台:</div>
      <div style="display: inline-block">
        <el-input v-model="name" placeholder="请输入图书名称" @keyup.enter.native="searchEnter">
          <el-select slot="prepend" collapse-tags @change="selectItem"
                     v-model="bindingPlatform"
                     style="width: 180px;" placeholder="请选择推送平台">
            <el-option
              v-for="platform in bindingPlatforms"
              :key="platform.id"
              :label="platform.name"
              :value="platform.id">
            </el-option>
          </el-select>
          <i class="el-input__icon el-icon-search" slot="prefix"></i>
          <el-button :icon="appendIcon" slot="append" v-on:click="switchAppend"></el-button>
        </el-input>
      </div>
    </div>
    <div id="advance" style="padding: 10px;float: right" v-if="showAdvance">
      <div class="block" style="margin-top: 10px">
        <div style="width: 100px;display: inline-block;text-align: right">图书分类</div>
        <el-cascader v-model="category"
                     :options="bookSubTagList"
                     filterable
                     :props="{label: 'name', value: 'id', checkStrictly: true }"
                     clearable size="small" style="width: 300px;"></el-cascader>
      </div>
      <div class="block" style="margin-top: 10px">
        <div style="width: 100px;display: inline-block;text-align: right">ISBN号</div>
        <div style="display: inline-block">
          <el-input v-model="ISBN" size="small" style="width: 300px;"></el-input>
        </div>
      </div>
      <div class="block"style="margin-top: 10px">
        <div style="width: 100px;display: inline-block;text-align: right">版本号</div>
        <div style="display: inline-block">
          <el-input v-model="version" size="small" style="width: 300px;"></el-input>
        </div>
      </div>
      <div class="block" style="margin-top: 10px">
        <div style="width: 100px;display: inline-block;text-align: right">推送时间</div>
        <div class="block" style="display: inline-block;">
          <el-date-picker
            v-model="updateTime"
            type="datetimerange"
            @change="dateChange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format=" yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"
            size="small" style="width: 300px;">
          </el-date-picker>
        </div>
      </div>
      <div style="width: 100px;display: inline-block;text-align: right;margin-top: 15px">状态</div>
      <div style="display: inline-block">
        <el-select placeholder="状态" size="small" style="width: 300px;" v-model="syncStatus">
          <el-option
            v-for="item in CONST.SYNC_STATUS"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </div>
      <div style="margin-top: 60px; right: 10px;">
        <el-row>
          <el-col :offset="6" :span="6">
            <div style="margin-left: 90px;height: 32px; width: 88px;">
              <el-button size="small" v-on:click="advanceCancel">取 消</el-button>
            </div>
          </el-col>
          <el-col :offset="2" :span="2">
            <div style="margin-left: 30px;height: 32px; width: 88px;">
              <el-button size="small" v-on:click="reset">重置</el-button>
            </div>
          </el-col>
          <el-col :offset="2" :span="2">
            <div div style="margin-left: 30px;height: 32px; width: 88px;">
              <el-button size="small" type="success" v-on:click="searchEnter">确 定</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import Label from "../calculator/exportModel/Label";

export default {
  components: {Label},
  props: ['bookSubTagList'],
  data() {
    return {
      showAdvance: false,
      appendIcon: "el-icon-caret-bottom",
      name: '',
      category: [],
      OfficialSearchData: [],
      syncStatus: '',
      updateTime: '',
      ISBN: '',
      bindingPlatforms: [],
      bindingPlatform: '',
      version:''
    }
  },
  methods: {
    switchAppend: function () {
      if (this.showAdvance) {
        this.showAdvance = false;
        this.appendIcon = "el-icon-caret-bottom";
      } else {
        this.showAdvance = true;
        this.appendIcon = "el-icon-caret-top";
      }
    },
    advanceCancel: function () {
      this.showAdvance = false;
    },
    reset: function () {
      this.name = ''
      this.category = []
      this.updateTime = ''
      this.ISBN = ''
      this.syncStatus = ''
      this.version=''
    },
    dateChange(val) {
      this.updateTime = val;
      if (val == null) {
        this.updateTime = ''
      }
    },
    getBindingPlatforms() {
      this.axios.get("/pmph/action/knowledgeLib/selectAllPlatforms", {
        params: {
          type: CONST.SYSTEM.BOOK
        }
      }).then((res) => {
        this.bindingPlatforms = res.data.platforms;
        if (this.bindingPlatforms.length > 0) {
          this.bindingPlatform = this.bindingPlatforms[0].id;
          this.$emit('advanceConfirm', 'isFromChild');
        }
      }).catch((err) => {
        console.error(err)
      })
    },
    selectItem(val) {
      this.bindingPlatform = val;
      this.$emit('advanceConfirm', 'isFromChild');
    },
    searchEnter() {
      this.advanceCancel();
      this.$emit('advanceConfirm', 'isFromChild');
    }
  },
  created() {
    this.getBindingPlatforms();
  }
}
</script>

<style scoped>

</style>
